Skip to content

fix(codegen-ts): remove EFAULT-prone recursive rm from gen temp cleanup - #628

Merged
dmealing merged 5 commits into
mainfrom
fm/mo-main-ci-flakes
Nov 21, 2026
Merged

dmealing merged 5 commits into
mainfrom
fm/mo-main-ci-flakes

Conversation

@dmealing

Copy link
Copy Markdown
Member

What Changed

  • codegen-ts runGen now deletes its untracked gen-state dir through a new src/scratch-dir.ts helper (removeTree) instead of Bun's recursive rmSync. The helper walks the tree with readdir/unlink/rmdir and treats an already-missing path as success. Its per-run temp dir honors DEV_SCRATCH via scratchRoot(). The codegen-ts tests that create temp dirs now use makeScratchDir/removeTree, and CONTRIBUTING.md says new codegen-ts tests should do the same.
  • integration-tests report-views-sqlite.test.ts puts its throwaway SQLite database under DEV_SCRATCH when set, sets PRAGMA synchronous = OFF for it, and uses a local walk-based remover in place of rmSync.
  • local-ci.yml notify job switches notify-send from -u critical to -u normal, so the "local-ci FAILED" desktop popup auto-dismisses. The GitHub email notification is unchanged.
Validation

Risk Assessment

✅ Low: Change is test-infrastructure and CI-notification only. The one src change swaps tmpdir()/rmSync for a scratch helper with a readdir/unlink/rmdir walker that treats ENOENT as success. Each intent item is covered: notify-send is now -u normal, the EFAULT rm sites go through removeTree, and the sqlite convergence test moves its DB to RAM with synchronous=OFF.

Testing

Both changes exercised; overall result pass. The workflow change ran the real extracted notify step and real notify-send on a private bus with a disposable notification daemon: the shipped step sends urgency normal and the pre-fix step sends critical. The flaky-test fix passed all affected codegen-ts and report-views-sqlite tests, including 12 parallel stress runs, and the removeTree adversarial checks passed. Not verified here: the GitHub email, which fires on the GitHub side, and reproduction of the original EFAULT/timeout on the base commit, since the race is intermittent and was not reproduced in this run. Broad regression came from the configured test command scripts/ci-local.sh --affected --strict-toolchains, which passed at target 858ba00.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
local-ci failure popup is sent at normal urgency, not critical (workflow notify step on private bus, real notify-send, disposable notification daemon) ✅ pass live notify-calls.jsonl; workflow-notify-step-shipped.sh; workflow-notify-step-prefix-critical.sh
GitHub failure email still fires after the notify change ⏸️ untested no The email is sent by GitHub's notification system, outside this workspace. The step's || echo fallback keeps the job green in either case. Verifying needs a real failed run on GitHub Actions and the…
codegen-ts runGen tests (run-gen, package-layout-root-declared, vo-only-config-optional, scratch-dir) stay green under 8-way concurrency after the removeTree/scratch-dir change ✅ pass live stress-summary.txt
migrate-ts report-views-sqlite convergence test stays green under 4-way concurrency with the DB on DEV_SCRATCH and synchronous=OFF ✅ pass live stress-summary.txt
removeTree removes populated trees, never follows symlinks, tolerates absent paths; scratch dirs land under DEV_SCRATCH (adversarial) ✅ pass live removetree-adversarial.out
Evidence: Recorded Notify D-Bus calls: shipped step urgency=1, pre-fix critical urgency=2
{"app_name": "notify-send", "summary": "local-ci FAILED: metaobjects", "body": "feat: sample commit subject\nhttps://example.invalid/run/1", "urgency": 1, "timeout": -1}
{"app_name": "notify-send", "summary": "local-ci FAILED: metaobjects", "body": "feat: sample commit subject\nhttps://example.invalid/run/1", "urgency": 2, "timeout": -1}
Evidence: Workflow notify step as shipped (run on private bus)
export DBUS_SESSION_BUS_ADDRESS="unix:path=/mnt/scratch/notify-live-2834449/bus.sock"
notify-send -u normal "local-ci FAILED: metaobjects" \
  "$(printf '%s' "$HEAD_MSG" | head -n1)
$RUN_URL" || echo "notify-send unavailable; GitHub email still fires"
Evidence: Pre-fix notify step with -u critical (contrast)
export DBUS_SESSION_BUS_ADDRESS="unix:path=/mnt/scratch/notify-live-2834449/bus.sock"
notify-send -u critical "local-ci FAILED: metaobjects" \
  "$(printf '%s' "$HEAD_MSG" | head -n1)
$RUN_URL" || echo "notify-send unavailable; GitHub email still fires"
Evidence: Disposable notification daemon used for the live urgency check
# Disposable notification daemon on a private session bus: records Notify calls, nothing else.
import sys, json
import dbus, dbus.service
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
DBusGMainLoop(set_as_default=True)
log = sys.argv[1]
class Srv(dbus.service.Object):
    @dbus.service.method("org.freedesktop.Notifications", in_signature="", out_signature="ssss")
    def GetServerInformation(self):
        return ("fake-notifyd", "metaobjects-validation", "0.0", "1.2")
    @dbus.service.method("org.freedesktop.Notifications", in_signature="", out_signature="as")
    def GetCapabilities(self):
        return ["body"]
    @dbus.service.method("org.freedesktop.Notifications", in_signature="susssasa{sv}i", out_signature="u")
    def Notify(self, app, rid, icon, summary, body, actions, hints, timeout):
        rec = {"app_name": str(app), "summary": str(summary), "body": str(body),
               "urgency": int(hints["urgency"]) if "urgency" in hints else None,
               "timeout": int(timeout)}
        with open(log, "a") as f: f.write(json.dumps(rec) + "\n")
        return 1
bus = dbus.SessionBus()
name = dbus.service.BusName("org.freedesktop.Notifications", bus)
Srv(bus, "/org/freedesktop/Notifications")
print("ready", flush=True)
GLib.MainLoop().run()
Evidence: removeTree adversarial run output
victim removed: true
symlink target survives: true
absent path second removal: no throw
scratch under DEV_SCRATCH: true /mnt/scratch
made scratch removed: true
Evidence: Stress run summary (8x codegen-ts, 4x report-views-sqlite)
 28 pass
 0 fail
Ran 28 tests across 4 files. [3.84s]
 28 pass
 0 fail
Ran 28 tests across 4 files. [4.58s]
 28 pass
 0 fail
Ran 28 tests across 4 files. [4.32s]
 28 pass
 0 fail
Ran 28 tests across 4 files. [4.18s]
 28 pass
 0 fail
Ran 28 tests across 4 files. [4.31s]
 28 pass
 0 fail
Ran 28 tests across 4 files. [4.47s]
 28 pass
 0 fail
Ran 28 tests across 4 files. [3.90s]
 28 pass
 0 fail
Ran 28 tests across 4 files. [4.56s]
 22 pass
 0 fail
Ran 22 tests across 1 file. [4.96s]
 22 pass
 0 fail
Ran 22 tests across 1 file. [4.88s]
 22 pass
 0 fail
Ran 22 tests across 1 file. [4.99s]
 22 pass
 0 fail
Ran 22 tests across 1 file. [4.73s]

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
local-ci failure popup is sent at normal urgency, not critical (workflow notify step on private bus, real notify-send, disposable notification daemon) ✅ pass live notify-calls.jsonl; workflow-notify-step-shipped.sh; workflow-notify-step-prefix-critical.sh
GitHub failure email still fires after the notify change ⏸️ untested no The email is sent by GitHub's notification system, outside this workspace. The step's || echo fallback keeps the job green in either case. Verifying needs a real failed run on GitHub Actions and the…
codegen-ts runGen tests (run-gen, package-layout-root-declared, vo-only-config-optional, scratch-dir) stay green under 8-way concurrency after the removeTree/scratch-dir change ✅ pass live stress-summary.txt
migrate-ts report-views-sqlite convergence test stays green under 4-way concurrency with the DB on DEV_SCRATCH and synchronous=OFF ✅ pass live stress-summary.txt
removeTree removes populated trees, never follows symlinks, tolerates absent paths; scratch dirs land under DEV_SCRATCH (adversarial) ✅ pass live removetree-adversarial.out
  • scripts/ci-local.sh --affected --strict-toolchains
  • Baseline (not re-run): scripts/ci-local.sh --affected --strict-toolchains passed at target 858ba00a6e.
  • Extracted the notify job step from .github/workflows/local-ci.yml with yq/python and ran it with real notify-send on a private dbus-daemon session bus (/mnt/scratch/notify-live-2834449/bus.sock). The bus address was pointed at the private bus; the rest of the step ran as shipped.
  • Disposable notification daemon fake_notifyd.py (dbus-py) on the private bus recorded Notify calls. Shipped step gave urgency=1; the pre-fix -u critical variant gave urgency=2.
  • bun test packages/codegen-ts/test/scratch-dir.test.ts packages/codegen-ts/test/run-gen.test.ts packages/codegen-ts/test/package-layout-root-declared.test.ts packages/codegen-ts/test/vo-only-config-optional.test.ts (28 pass, 0 fail), run from server/typescript.
  • bun test packages/integration-tests/test/report-views-sqlite.test.ts (22 pass, 0 fail).
  • Stress: 8 parallel runs of the codegen-ts set and 4 parallel runs of report-views-sqlite, all exit 0 (summary in stress-summary.txt).
  • Adversarial: ran removeTree/makeScratchDir/scratchRoot from codegen-ts/src/scratch-dir.ts in Bun against a populated tree with a symlink to an outside dir, a repeated removal of an absent path, and a DEV_SCRATCH-rooted scratch dir. Output in removetree-adversarial.out.
  • Cleanup: stopped the private dbus-daemon, dbus-monitor and fake notification daemon by process group. Removed run scratch dir. git status clean.
  • Side effect disclosed: on the first attempt, the fake notification daemon ran without DBUS_SESSION_BUS_ADDRESS set and attached to the operator's real session bus for a few seconds. I stopped it by process group, and the rerun used only the private bus. No real notification was sent by the test steps.
⚠️ **Document** - 1 info
  • ℹ️ CONTRIBUTING.md:93 - CONTRIBUTING.md: added a paragraph that codegen-ts tests needing temp dirs use makeScratchDir/removeTree from src/scratch-dir.ts, not mkdtempSync and rmSync recursive, because Bun's recursive rmSync can EFAULT under parallel load. Done.
  • ℹ️ Many codegen-ts tests and scripts still use mkdtempSync and rmSync recursive. Migrating them to the scratch helpers is a code change (out of docs scope). Candidate follow-up if the EFAULT flake recurs.
  • ℹ️ CHANGELOG.md - No CHANGELOG [Unreleased] entry added. The runGen temp-location change is internal (only visible when DEV_SCRATCH is set) and the test/CI fixes are not user-facing. Judgment call; add one if the maintainer wants the flake fix recorded.

🔧 Fix applied.
1 info still open:

  • ℹ️ server/typescript/packages/codegen-ts/test - Raw mkdtempSync and recursive rmSync remain in about 537 sites across about 130 codegen-ts test, src and script files. The user-chosen migration to makeScratchDir/removeTree is code and test work, outside the docs-only phase. Scope is much larger than the 120-line / 20-file estimate. Not done here.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…smiss

- local-ci notify-send -u normal (was critical, never auto-dismissed)
- codegen-ts: per-run/test temp dirs under $DEV_SCRATCH; race-safe removeTree falls back to a manual walk on Bun's intermittent rm EFAULT
- integration-tests report-views-sqlite: DB in scratch and synchronous=OFF; setup fsync made each test ~1.3s, past the 5s timeout under disk load
…hange. One contributor-rule edit in CONTRIBUTING.md; no other stale facts found.
@dmealing
dmealing merged commit 9578cff into main Nov 21, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-main-ci-flakes branch November 21, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant